﻿using MediatR;
using S.EarTag.API.Application.MediatorCommand.ProductionGradingCommand;
using S.EarTag.Domain.Model;
using S.EarTag.Infrastructure.Repository.Interface.IRepository;

namespace S.EarTag.API.Application.MediatorCommandHandler.ProductionGradingCommandHandler
{
    public class ProductionGradingCreateCommandHandler : IRequestHandler<ProductionGradingCreateCommand, bool>
    {
        private readonly IProductionGradingRepository _productionGradingRepository;
        public ProductionGradingCreateCommandHandler(IProductionGradingRepository productionGradingRepository)
        {
            _productionGradingRepository = productionGradingRepository;
        }
        /// <summary>
        /// 添加生产定级数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<bool> Handle(ProductionGradingCreateCommand request, CancellationToken cancellationToken)
        {
            return await _productionGradingRepository.AddAsync(new ProductionGrading
            {
                RankEarTag = request.RankEarTag,
                Prime = request.Prime,
                Currents = request.Currents,
                CreateBy = request.CreateBy,
                CreateDate = request.CreateDate,
                UpdateBy =  request.UpdateBy,
                UpdateDate= request.UpdateDate,
            });
        }
    }
}
